package Thread;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-08-10
 * Time: 20:51
 */
public class demo33 {
    private static AtomicInteger count = new AtomicInteger(0);

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 50000; i++) {
                count.getAndIncrement();//相当于int类型的count++
//                count.incrementAndGet();//相当于int类型的++count
//                count.getAndDecrement();//相当于int类型的count--
//                count.decrementAndGet();//相当于int类型的--count
//                count.getAndAdd(1);//相当于相当于int类型的count+=1
            }
        });
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 50000; i++) {
                count.getAndIncrement();
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println("count = " + count.get());//通过get来拿到原子类内部的真实数据
    }
}
